package it.cast.wechat.dto;

import com.fasterxml.jackson.annotation.JsonFormat;
import it.cast.wechat.pojo.Address;
import it.cast.wechat.pojo.Orders;
import it.cast.wechat.utils.IDUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.Date;
import java.util.List;

public class OrderVo {
    private String orderId;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    private Date orderTime;

    private Double total;

    private Integer state;

    private String userId;

    private String describess;

    private Address address;

    private List<OrderItemVo> orderItems;

    public List<OrderItemVo> getOrderItems() {
        return orderItems;
    }

    public void setOrderItems(List<OrderItemVo> orderItems) {
        this.orderItems = orderItems;
    }

    public String getOrderId() {
        return orderId;
    }

    public void setOrderId(String orderId) {
        this.orderId = orderId == null ? null : orderId.trim();
    }

    public Date getOrderTime() {
        return orderTime;
    }

    public void setOrderTime(Date orderTime) {
        this.orderTime = orderTime;
    }

    public Double getTotal() {
        return total;
    }

    public void setTotal(Double total) {
        this.total = total;
    }

    public Integer getState() {
        return state;
    }

    public void setState(Integer state) {
        this.state = state;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId == null ? null : userId.trim();
    }


    public Address getAddress() {
        return address;
    }

    public void setAddress(Address address) {
        this.address = address;
    }

    public String getDescribess() {
        return describess;
    }

    public void setDescribess(String describess) {
        this.describess = describess;
    }

    public Orders builderOrders(){
        Orders orders = new Orders();
        if(StringUtils.isEmpty(this.orderId)){
            orders.setOrderId(IDUtils.getOrderId());
        }else {
            orders.setOrderId(this.orderId);
        }
        if(this.orderTime == null){
            orders.setOrderTime(new Date());
        }else {
            orders.setOrderTime(this.orderTime);
        }
        if(this.state == null){
            orders.setState(0);
        }else {
            orders.setState(this.state);
        }
        orders.setAddressId(this.address.getAddressId());
        orders.setDescribess(this.describess);
        orders.setTotal(this.total);
        orders.setUserId(this.userId);
        return orders;
    }
}
